package org.jeecg.modules.demo.fapiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.demo.fapiao.entity.BusFapiao;
import org.jeecg.modules.demo.fapiao.mapper.BusFapiaoMapper;
import org.jeecg.modules.demo.fapiao.service.IBusFapiaoService;
import org.springframework.stereotype.Service;

/**
 * @Description: 发票抬头
 * @Author: jeecg-boot
 * @Date: 2021-07-17
 * @Version: V1.0
 */
@Service
public class BusFapiaoServiceImpl extends ServiceImpl<BusFapiaoMapper, BusFapiao> implements IBusFapiaoService {

    @Override
    public void saveOrUpdateFapiao(BusFapiao busFapiao) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = sysUser.getId();
        BusFapiao one = baseMapper.selectOne(new QueryWrapper<BusFapiao>().eq("user_id", userId));
        if (null != one) {
            busFapiao.setId(one.getId());
            baseMapper.updateById(busFapiao);
        } else {
            busFapiao.setUserId(userId);
            baseMapper.insert(busFapiao);
        }
    }
}
